package com.pms.controller;

import com.pms.dto.MailBoxPageQueryDTO;
import com.pms.dto.MailboxSaveDTO;
import com.pms.dto.MailboxUpdateDTO;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.MailboxService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.users.MemoryUserDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "信箱相关接口")
@RestController
@RequestMapping("/mailbox")
@Slf4j
public class MailBoxController {

    @Autowired
    private MailboxService mailboxService;

    @ApiOperation("信箱新增")
    @PostMapping("/save")
    public Result<String> save(@RequestBody MailboxSaveDTO mailboxSaveDTO){
        log.info("信箱新增，{}",mailboxSaveDTO);
        mailboxService.save(mailboxSaveDTO);
        return Result.success();
    }

    @ApiOperation("信箱分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(MailBoxPageQueryDTO mailBoxPageQueryDTO){
        log.info("信箱分页查询,{}",mailBoxPageQueryDTO);
        PageResult pageResult=mailboxService.page(mailBoxPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/delete")
    public Result<String> deleteBatch(@RequestParam List<Integer> ids){
        log.info("批量删除，{}",ids);
        mailboxService.deleteBatch(ids);
        return Result.success();
    }

    @ApiOperation("信箱信息修改")
    @PutMapping("/update")
    public Result<String> update(@RequestBody MailboxUpdateDTO mailboxUpdateDTO){
        log.info("信箱信息修改,{}",mailboxUpdateDTO);
        mailboxService.update(mailboxUpdateDTO);
        return Result.success();
    }
}
